/*
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
# The Original Code is Copyright (C) 2009 by exherb (htpp://4leaf.me).
# All rights reserved.
#
# The Original Code is: all of this file.
#
# Contributor(s): none yet.
#
*/
#ifndef TRANSTATE_PNG_H_
#define TRANSTATE_PNG_H_

#include <string>
#include <Windows.h>

#include "../include/iTunesMobileDevice.h"

typedef CFWriteStreamRef (*tf_CFWriteStreamCreateWithFile)(CFAllocatorRef, CFURLRef);
typedef void (*tf_CFWriteStreamClose)( CFWriteStreamRef);
typedef CFReadStreamRef (*tf_CFReadStreamCreateWithFile)(CFAllocatorRef, CFURLRef);
typedef CFStringRef (*tf_CFStringCreateWithCString)(CFAllocatorRef, const char *, unsigned int) ;
typedef CFURLRef (*tf_CFURLCreateWithFileSystemPath)(CFAllocatorRef, CFStringRef, signed long, unsigned char);
typedef unsigned char (*tf_CFReadStreamOpen)(CFReadStreamRef);
typedef unsigned char (*tf_CFWriteStreamOpen)(CFWriteStreamRef);
typedef const void * (*tf_CFPropertyListCreateFromStream)(CFAllocatorRef, CFReadStreamRef, signed long, unsigned long,signed long *,CFStringRef *);
typedef void (*tf_CFReadStreamClose)(CFReadStreamRef);
typedef unsigned char (*tf_CFPropertyListIsValid)( const void *,signed long);
typedef signed long (*tf_CFPropertyListWriteToStream)( const void *,CFWriteStreamRef,signed long,CFStringRef *) ;
typedef void (*tf_CFRelease)(const void * cf);
typedef unsigned char (*tf_CFURLCreateDataAndPropertiesFromResource)(CFAllocatorRef alloc, CFURLRef url, CFDataRef *resourceData, CFDictionaryRef *properties, CFArrayRef desiredProperties, signed int *errorCode);
typedef const void * (*tf_CFPropertyListCreateFromXMLData)(CFAllocatorRef allocator, CFDataRef xmlData, unsigned long mutabilityOption, CFStringRef *errorString);
typedef CFDataRef (*tf_CFPropertyListCreateXMLData)(CFAllocatorRef allocator,  const void * propertyList);
typedef unsigned char (*tf_CFURLWriteDataAndPropertiesToResource)(CFURLRef url, CFDataRef dataToWrite, CFDictionaryRef propertiesToWrite, signed int *errorCode);

class CHTranslatePlist
{

public:
	CHTranslatePlist(const std::wstring &coreFundationPath);
	~CHTranslatePlist(void);

	bool BinaryToXML(const wchar_t *src, const wchar_t *dst);
	bool XMLToBinary(const wchar_t *src, const wchar_t *dst);
	
private:
	std::string UTF16ToUTF8(const std::wstring &utf16Str);

	static HMODULE										m_coreFundationDllHandle;
	static bool											m_isInited;
	static tf_CFWriteStreamCreateWithFile				CFWriteStreamCreateWithFile;
	static tf_CFReadStreamCreateWithFile				CFReadStreamCreateWithFile;
	static tf_CFStringCreateWithCString					CFStringCreateWithCString;
	static tf_CFURLCreateWithFileSystemPath				CFURLCreateWithFileSystemPath;
	static tf_CFReadStreamOpen							CFReadStreamOpen;
	static tf_CFWriteStreamOpen							CFWriteStreamOpen;
	static tf_CFPropertyListCreateFromStream			CFPropertyListCreateFromStream;
	static tf_CFReadStreamClose							CFReadStreamClose;
	static tf_CFPropertyListIsValid						CFPropertyListIsValid;
	static tf_CFPropertyListWriteToStream				CFPropertyListWriteToStream;
	static tf_CFWriteStreamClose						CFWriteStreamClose;
	static tf_CFRelease									CFRelease;
	static tf_CFURLCreateDataAndPropertiesFromResource	CFURLCreateDataAndPropertiesFromResource;
	static tf_CFPropertyListCreateFromXMLData           CFPropertyListCreateFromXMLData;
	static tf_CFPropertyListCreateXMLData               CFPropertyListCreateXMLData;
	static tf_CFURLWriteDataAndPropertiesToResource     CFURLWriteDataAndPropertiesToResource;

};

#endif